JavaScript syntax
part 41/43 Β· 161.3 KB total
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Native functions and methods
eval (expression)
Evaluates the first parameter as an expression, which can include
assignment statements. Variables local to functions can be referenced by
the expression. However, eval represents a major security risk, as it
allows a bad actor to execute arbitrary code, so its use is
discouraged.cite-ref-deve-eval-27-0[27]
> (function foo() {
... var x = 7;
... console.log("val " + eval("x + 2"));
... })();
val 9
undefined
See also
References
cite-note-11. β "JavaScript 1.1 specification". Archived from the original on 26 February 2017. Retrieved 19 April 2006.
cite-note-22. β "Chapter 1. Basic JavaScript". speakingjs.com. Archived from the original on 10 February 2022. Retrieved 22 September 2020.
cite-note-44. β citereffariasFarias, Bradley. "Hashbang Grammar". GitHub. Retrieved 13 July 2025.
cite-note-55. β "Storing the information you need β Variables - Learn web development | MDN". developer.mozilla.org. 9 May 2023. Retrieved 23 June 2023.
cite-note-66. β "Values, Variables, and Literals - MDC". Mozilla Developer Network. 16 September 2010. Archived from the original on 29 June 2011. Retrieved 1 February 2020.
cite-note-88. β "JavaScript Scoping and Hoisting Archived 8 May 2021 at the Wayback Machine", Ben Cherry Archived 28 February 2021 at the Wayback Machine, Adequately Good Archived 8 March 2022 at the Wayback Machine, 8 February 2010
cite-note-99. β ECMA-262 5e edition clarified this behavior with the Declarative Environment Record and Object Environment Record. With this formalism, the global object is the Object Environment Record of the global Lexical Environment (the global scope).
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ